package bean;

import json.person;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "login_dgut")
public class login_dgut extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        MakeLogin(request,response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        MakeLogin(request,response);

    }

    protected  void MakeLogin(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        person dgut=(person) request.getSession().getAttribute("USER");
        User user=null;
        if(dgut!=null)
        {
            user=function.LoginDgutUser(dgut);
            if(user!=null)
            {
                if(user.getUsername().equals("游客"))
                {
                    request.getSession().setAttribute("LocalUser",user);
                    response.sendRedirect("/dgut_makeName.jsp");
                }
                else
                {
                    request.getSession().setAttribute("LocalUser",user);
                    response.sendRedirect("/interface.jsp");
                }
            }
            else response.sendRedirect("/error.jsp");
        }
        else response.sendRedirect("/error.jsp");
    }
}
